package com.hmall.user.config;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class TestFilter extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
//        String str = request.getHeader("authorization");
//
//        if ("2".equals(str)){
//            System.out.println("authorization = " + str);
//            UserContextHolder.holder.set(str);
//            return true;
//        }
//        return false;
        String str = request.getHeader("authorization");
        if (str == null || str.equals("")) {
            System.out.println("非法的请求"+request.getRequestURI());
            response.setStatus(403);
            return false;
        }
        System.out.println("authorization = " + str);
        UserContextHolder.holder.set(str);
        return true;
    }


}
